package com.zy.web.controller.business;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.business.domain.TbDocument;
import com.zy.business.domain.TbDocumentFolder;
import com.zy.business.service.DocumentService;
import com.zy.common.annotation.Log;
import com.zy.common.core.controller.BaseController;
import com.zy.common.core.domain.AjaxResult;
import com.zy.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 文档管理接口
 * @author: whf
 * @create: 2023-02-24 15:29
 **/
@RestController
@Api(tags = "文档管理接口")
@RequestMapping("/document")
public class DocumentController extends BaseController {

    @Autowired
    private DocumentService documentService;

    @ApiOperation("查看文档库中的文件列表")
    @GetMapping("/list")
    public AjaxResult list(@RequestParam Long documentFolderId) {
        List<TbDocument> documentList = documentService.list(new QueryWrapper<TbDocument>().eq("document_folder_id",documentFolderId));
        return AjaxResult.success(documentList);
    }

    @ApiOperation(value = "新增文档")
    @Log(title = "文档管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TbDocumentFolder documentFolder){
        return documentService.addDocument(documentFolder);
    }

    @ApiOperation(value = "删除文档")
    @Log(title = "文档管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{documentId}")
    public AjaxResult delete(@PathVariable Long documentId){
        return toAjax(documentService.deleteDocument(documentId));
    }
}
